# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=oras-cli
pkgver=1.1.0
pkgrel=2
pkgdesc="OCI registry client"
url="https://oras.land/cli"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/oras-project/oras/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/oras-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X oras.land/oras/internal/version.Version=$pkgver
	-X oras.land/oras/internal/version.BuildMetadata=
	-X oras.land/oras/internal/version.GitCommit=AlpineLinux
	-X oras.land/oras/internal/version.GitTreeState=clean
	"
	go build -v -ldflags "$_goldflags" ./cmd/oras

	for shell in bash fish zsh; do
		./oras completion $shell > oras.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 oras -t "$pkgdir"/usr/bin/

	install -Dm644 oras.bash \
		"$pkgdir"/usr/share/bash-completion/completions/oras
	install -Dm644 oras.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/oras.fish
	install -Dm644 oras.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_oras
}

sha512sums="
2353a879ca7ff62f2933c2548c3b16e4dafb0b18a6428cb6722121c6961486d821e4caf4d853854cfb5879fcc97338490f6273660ad4235fc9277ad3797071c3  oras-cli-1.1.0.tar.gz
"
